package com.stars.module.privilege.controller;

import com.stars.base.entity.CommonDTO;
import com.stars.base.entity.Result;
import com.stars.module.privilege.entity.StarPrivilege;
import com.stars.module.privilege.service.StarPrivilegeService;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author : Rocks
 * @version : 1.0
 * @date : 2022/11/27 21:01
 * @description : 权限控制器
 */
@RestController
@RequestMapping("starPrivilege")
public class StarPrivilegeController {

    private final StarPrivilegeService service;

    public StarPrivilegeController(StarPrivilegeService service) {
        this.service = service;
    }

    /**
     * 保存或者更新权限对象
     * @author : Rocks
     * @date :  2023/2/25 23:11
     * @param privilege 权限对象
     * @return Result
     */
    @RequestMapping("/saveOrUpdate")
    public Result saveOrUpdatePrivilege(@RequestBody StarPrivilege privilege){
        return Result.result(service.saveOrUpdatePrivilege(privilege));
    }

    /**
     * 删除指定ID的权限对象
     * @author : Rocks
     * @date :  2023/2/25 23:11
     * @param id 要删除权限ID
     * @return Result
     */
    @RequestMapping("/remove")
    public Result removePrivilege(String id){
        return Result.result(service.removePrivilege(id));
    }

    @RequestMapping("/loadTree")
    public Result loadTree(){
        return Result.success(service.loadTree());
    }

    @RequestMapping("/loadDataListByFid")
    public Result loadDataListByFid(@RequestBody CommonDTO dto) {
        return Result.success(service.loadDataListByFid(dto));
    }

    @RequestMapping("/loadPrivilegeById")
    public Result loadPrivilegeById(String id){
        return Result.success(service.loadPrivilegeById(id));
    }

    @RequestMapping("/getMaxIndex")
    public Result getMaxIndex(String fid){
        return Result.success(service.getMaxIndex(fid));
    }

    @RequestMapping("/loadSelectTree")
    public Result loadSelectTree () {
        return Result.success(service.loadSelectTree());
    }
}
